package com.winshare.saleAssistant.service.impl;

import com.winshare.saleAssistant.dao.SysParamMapper;
import com.winshare.saleAssistant.domain.dto.req.ParamCreateDTO;
import com.winshare.saleAssistant.domain.entity.SysParamDO;
import com.winshare.saleAssistant.mapper.SysParamMapStruct;
import com.winshare.saleAssistant.service.SysParamService;
import org.springframework.stereotype.Service;

@Service
public class SysParamServiceImpl implements SysParamService {

    private final SysParamMapper sysParamMapper;

    public SysParamServiceImpl(SysParamMapper sysParamMapper) {
        this.sysParamMapper = sysParamMapper;
    }

    @Override
    public void saveSysParam(ParamCreateDTO paramCreateDTO) {
        SysParamDO sysParamDO = SysParamMapStruct.INSTANCE.fromParamCreateDTO(paramCreateDTO);
        SysParamDO sysParamDOInSql = sysParamMapper.getSysParam();
        if(null == sysParamDOInSql) {
            sysParamMapper.saveSysParam(sysParamDO);
            return;
        }
        sysParamDO.setId(sysParamDOInSql.getId());
        sysParamMapper.updateSysParam(sysParamDO);
    }

    @Override
    public SysParamDO getSysParam() {
        return sysParamMapper.getSysParam();
    }
}
